/*
 * TileSet.java
 *
 * Created on 16. februar 2007, 10:18
 *
 * Company: HT++
 *
 * @author Magnus Hemmer Pihl
 * @version 1.0
 *
 */

package game.visual;

import java.awt.Image;
import java.io.File;
import javax.swing.ImageIcon;

public class TileSet
{
    private Image padTile;
    private Image ballTile;
    private Image brickTile;

    public static final String SKIN_LIBRARY = (new File("skins/")).getAbsolutePath() + File.separator;
    
    private static TileSet instance = new TileSet();
    
    /**
     * Initializes the TileSet object and loads the specified tileset.
     * @param path A path in the filesystem pointing to the initial tileset to be loaded.
     */
    public TileSet()
    {
	loadTileSet(SKIN_LIBRARY+"Arkanoid");
    }
    
    /**
     * Returns a reference to the Singleton instance of TileSet.
     * @return Singleton instance of TileSet.
     */
    public static TileSet getInstance()
    {
        return instance;
    }
    
    /**
     * Loads a new tileset, found at the specified path.
     * @param path A path in the filesystem pointing to the tileset to be loaded.
     * @return True on succes, false on failure.
     */
    public boolean loadTileSet(String path)
    {
        return this.loadTileSet(new File(path));
    }
    
    /**
     * Loads a new tileset, found at the specified path.
     * @param path A path in the filesystem pointing to the tileset to be loaded.
     * @return True on succes, false on failure.
     */
    public boolean loadTileSet(File file)
    {
        try
        {
            if(file.isDirectory())
            {
                String path = file.getAbsolutePath() + file.separator;
                padTile = new ImageIcon(path + "pad.png").getImage();
                ballTile = new ImageIcon(path + "ball.png").getImage();
		brickTile = new ImageIcon(path + "brick.png").getImage();
            }
            
            return true;
        }
        catch(Exception e)
        {
            //Most likely a FileNotFoundException
            return false;
        }
    }
    
    public Image getPadTile() { return padTile; }
    public int getPadWidth() { return padTile.getWidth(null); }
    public int getPadHeight() { return padTile.getHeight(null); }
    
    public Image getBallTile() { return ballTile; }
    public int getBallWidth() { return ballTile.getWidth(null); }
    public int getBallHeight() { return ballTile.getHeight(null); }
    
    public Image getBrickTile() { return brickTile; }
    public int getBrickWidth() { return brickTile.getWidth(null); }
    public int getBrickHeight() { return brickTile.getHeight(null); }
    
    /**
     * Reformats a string to have leading zeroes, up to the given final length.
     * @param string The string to be reformatted.
     * @param length The desired length of the string, after reformatting.
     * @return The reformatted string including leading zeroes.
     */
//    public static String zeroPad(String string, int length)
//    {
//        StringBuilder builder = new StringBuilder(length);
//        
//        for (int i = string.length(); i < length; i++)
//        {
//            builder.append('0');
//        }
//        
//        builder.append(string);
//        
//        return builder.toString();
//    }        
}